package cn.webrx.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Autowired
    private UserDetailsService userDetailsService;

    @Autowired
    private PasswordEncoder pwd;

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        //02
        //auth.inMemoryAuthentication().withUser("root").password(pwd.encode("root")).roles("admin");

        //03
        auth.userDetailsService(userDetailsService).passwordEncoder(pwd);
    }
}
